<?php

namespace App\Service\Third;

use AlibabaCloud\Client\Request\Request;
use App\Model\OcpcOppo;
use App\Service\BaseService;

/**
 * oppo监测链接
 */
class OppoAdService extends BaseService
{
    /**
     * https://xx.com/callback/oppo_ad?os=$os$&os_version=$ov$&net_type=$nt$&useragent=$ua$&model=$m$&lang=$lan$&country=$c$&pkg=$pkg$&app_version=$av$&referer=$rf$&carrier=$ca$&progress=$progress$&imei=$im$&oaid=__OAID__&ad_id=$ad$&ad_name=$an$&req_id=$req$&c_id=404
     */
    public function handle()
    {
        $params = $this->request->all();

        log_info('oppo监测链接===='.json_encode($params));
        $oaid = $params['oaid'] ?? '';
        $imei = $params['imei'] ?? '';
        $channel = $params['c_id'] ?? 0;

        if (OcpcOppo::existsOaid($oaid, $channel)) {
            return 1;
        }

        if (OcpcOppo::existImei($imei, $channel)) {
            return 1;
        }

        $ret = OcpcOppo::addLog($params);

        log_info(__CLASS__ . "==Ret:{$ret}==Params:" . json_encode($params));

        return $ret;
    }
}
